<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#--引入外部文件-->
    <#include "../common/header.ftl">

    <script type="application/javascript">
        $(function () {

            //添加&修改模态框
            $(".modifyBtn").click(function () {
                $("#inputModal input").val("");
                var obj = $(this).data("json");
                //console.log(obj);
                if (obj) {
                    $("#inputModal input[name='id']").val(obj.id);
                    $("#inputModal input[name='number']").val(obj.number);
                    $("#inputModal select[name='commodity.id']").val(obj.commodityId);
                }
                $("#inputModal").modal('show');
            })

        })

    </script>
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品库存管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/stock/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <a href="javascript:" class="btn btn-success modifyBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>商品名称</th>
                    <th>库存数量</th>
                    <th></th>
                </tr>
                <#--使用Freemark的指令完成循环迭代-->
                <#list (pageInfo.list)! as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.commodity.name}</td>
                        <td>${entity.number}</td>
                        <td>
                            <a href="javascript:" class="btn btn-danger btn-xs modifyBtn" data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-plus"></span> 修改库存
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--添加/修改商品-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/stock/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id"/>

                    <div class="form-group" >
                        <label class="col-lg-4 control-label">商品名称：</label>
                        <div class="col-lg-6">
                            <select name="commodity.id" class="form-control">
                            <#list commodities! as c>
                                <option value="${c.id}">${c.name}</option>
                            </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-lg-4 control-label">数量：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="number" />
                        </div>
                    </div>
                </form>
            </div>
            <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>